package cn.hywx.convert;

import java.util.concurrent.LinkedBlockingQueue;

import cn.hywx.convert.beans.DocumentBean;
/**
 * document handler queue
 * @author all3n
 *
 */
public class OfficeQueue {
	static int volume = 100;

	OfficeQueue(int vlo) {
		OfficeQueue.volume = vlo;
	}

	private LinkedBlockingQueue<DocumentBean> queue = new LinkedBlockingQueue<DocumentBean>(volume);
	
	public synchronized boolean pushDocument(DocumentBean docbean) throws InterruptedException {
		while(30 <= queue.size()){
			this.wait();
		}
		this.notify();
		if(!queue.contains(docbean)){
			queue.offer(docbean);
			return true;
		}else{
			return false;
		}
	}

	public synchronized DocumentBean popDocument() throws InterruptedException {
		while (0 >= queue.size()) {
			this.wait();
		}
		this.notify();
		return queue.take();
	}

	public int convertQueueSize() {
		return queue.size();
	}

	
}
